<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="600px" append-to-body>
    <div v-loading="loading">
      <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="false">

        <el-form-item label="报价状态:" prop="quotationStatus">
          <el-select v-model="form.quotationStatus" clearable reserve-keyword placeholder="报价状态">
            <el-option v-for="item in quote_status" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="记录填写:" prop="orderProgress">
          <el-input type="textarea" style="width: 600px" :rows="4" v-model="form.orderProgress"></el-input>
        </el-form-item>
      </el-form>
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm" :loading="loading">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import modelMixin from '@/mixins/modelMixin'
import quotation, { getQuotationCode } from '@/api/goods/quotation'
export default {
  name: 'addForm',
  mixins: [modelMixin],
  data() {
    return {
      open: false,
      title: '添加报价单',
      funcObj: quotation,
      form: {},
      supplierOptions: [],//客户
      quotationSchemeOptions: [],//方案
      rules: {
        clientId: [
          {
            required: true,
            message: '请选择客户',
            trigger: 'blur'
          }
        ],
        quotationStatus: [
          {
            required: true,
            message: '请选择报价状态',
            trigger: 'blur'
          }
        ],
        schemeId: [
          {
            required: true,
            message: '请选择报价方案',
            trigger: 'blur'
          }
        ],
        schemeId: [
          {
            required: true,
            message: '请选择报价方案',
            trigger: 'blur'
          }
        ],
      },
      queryParams: {
        categoryId: '',
        categoryName: ''
      },
      active: 1,
      baseInput: 200,
      data: [],
      dateRange: [],
      dataSource: [],
      loading: false,
      quote_status: [],//报价状态
    };
  },

  methods: {
    add() {
      this.open = true;
      this.title = '添加报价单',
        this.form = {}
      this.dataSource = []
      this.addInit();
      this.listQuotationSchemeAll();
      this.getSupplierAllList(1)
      this.getDicts('quote_status');
    },
    edit(row) {
      this.open = true;
      this.title = '进展记录',
        this.form = {}
      this.dataSource = []
      this.getDicts('quote_status');
      this.getDetail(row)
    },
    detailAfter() {
      this.dataSource = this.form.quotationItemVoList.map(v => {
        return {
          ...v,
          packImg: v.jzgGoodsVo && v.jzgGoodsVo.packImg || '',
          goodsName: v.jzgGoodsVo && v.jzgGoodsVo.goodsName || '',
          brandName: v.jzgGoodsVo && v.jzgGoodsVo.brandName || '',
        }
      })
    },
    // 获取报价单号
    addInit() {
      getQuotationCode().then(res => {
        this.form.quotationCode = res.data || res.msg;
      })
    },
    cancel() {
      this.open = false;
    },
    categoryChange(value) {
      this.form.categoryId = value;
    },
    handleSelectionChange(val) {
      this.multiple = val.length > 1;
    },
    selectHandle(row) {
      return 1;
    },
    handleAdd() {
      this.$refs.selectMaterialForm.show();
    },

    selectOk(data) {
      this.dataSource = data.map(v => {
        return {
          ...v,
          goodsId: v.id,
          surrogateStatus: v.supplyMode,
          shelfStatus: v.auditStatus,
          costPrice: v.costPrice,
          wholesalePrice: v.wholesalePrice
        }
      });
    },
    remoteMethod(query, listKey, key) {
      const optionKey = listKey + 'Options';
      if (query !== '') {

        this[optionKey] = this[listKey + 'List'].filter(item => {
          return item[key].toLowerCase()
            .indexOf(query.toLowerCase()) > -1;
        });
      } else {
        this[optionKey] = this[listKey + 'List'];
      }

    },

    classifyForm() {
      this.form.quotationItemList = this.dataSource
      // 价格
      this.form.averagePrice = this.dataSource.reduce((total, item) => {
        return total + +item.wholesalePrice
      }, 0) / this.dataSource.length
      // 金额
      this.form.quotationPrice = this.dataSource.reduce((total, item) => {
        return total + +item.wholesalePrice
      }, 0)
      console.log('this.form :>> ', this.form);
    }
  }
};
</script>

<style lang="scss" scoped></style>